﻿using System;
using UnityEngine;

namespace UnityEngineExtra
{
	// Token: 0x0200061A RID: 1562
	public class DontDestroyParent : MonoBehaviour
	{
		// Token: 0x06002587 RID: 9607 RVA: 0x001443B8 File Offset: 0x001425B8
		public virtual void Awake()
		{
			if (DontDestroyParent.Instance == this)
			{
				UnityEngine.Object.DontDestroyOnLoad(base.gameObject);
			}
			else
			{
				UnityEngine.Object.Destroy(base.gameObject);
			}
		}

		// Token: 0x06002588 RID: 9608 RVA: 0x001443E8 File Offset: 0x001425E8
		public virtual void OnLevelWasLoaded(int level)
		{
			UnityEngine.Object.Destroy(base.gameObject);
			DontDestroyParent.instance = null;
		}

		// Token: 0x06002589 RID: 9609 RVA: 0x001443FC File Offset: 0x001425FC
		public static void Register(GameObject obj)
		{
			obj.transform.parent = DontDestroyParent.Instance.transform;
		}

		// Token: 0x0600258A RID: 9610 RVA: 0x00144414 File Offset: 0x00142614
		public static void Register(MonoBehaviour component)
		{
			DontDestroyParent.Register(component.gameObject);
		}

		// Token: 0x17000401 RID: 1025
		// (get) Token: 0x0600258B RID: 9611 RVA: 0x00144424 File Offset: 0x00142624
		public static DontDestroyParent Instance
		{
			get
			{
				if (DontDestroyParent.instance == null)
				{
					DontDestroyParent.instance = UnityEngine.Object.FindObjectOfType<DontDestroyParent>();
					if (DontDestroyParent.instance == null)
					{
						GameObject gameObject = new GameObject("DontDestroyParent");
						DontDestroyParent.instance = gameObject.AddComponent<DontDestroyParent>();
					}
					DontDestroyParent.instance.gameObject.hideFlags = HideFlags.NotEditable;
				}
				return DontDestroyParent.instance;
			}
		}

		// Token: 0x04002D2D RID: 11565
		public static DontDestroyParent instance;
	}
}
